#include "strategy_info.h"

int StrategyInfo::GetConfigInt(const std::string& name, int32_t& value) const
{
    std::map<std::string, std::string>::const_iterator iter = m_configMap.find(name);
    if(iter != m_configMap.end())
    {
        value = atoi(iter->second.c_str());
        return 0;
    }
    else
    {
        WARNING("config name[%s] is not exit!", name.c_str());
        return -1;
    }
}
int StrategyInfo::GetConfigLong(const std::string& name, long int& value) const
{
    std::map<std::string, std::string>::const_iterator iter = m_configMap.find(name);
    if(iter != m_configMap.end())
    {
        value = atol(iter->second.c_str());
        return 0;
    }
    else
    {
        WARNING("config name[%s] is not exit!", name.c_str());
        return -1;
    }
}
int StrategyInfo::GetConfigDouble(const std::string& name, double& value) const
{
    std::map<std::string, std::string>::const_iterator iter = m_configMap.find(name);
    if(iter != m_configMap.end())
    {
        value = atof(iter->second.c_str());
        return 0;
    }
    else
    {
        WARNING("config name[%s] is not exit!", name.c_str());
        return -1;
    }
}
int StrategyInfo::GetConfigBool(const std::string& name, bool& value) const
{
    std::map<std::string, std::string>::const_iterator iter = m_configMap.find(name);
    if(iter != m_configMap.end())
    {
        if(iter->second == "true")
        {
            value = true;
            return 0;
        }
        else if(iter->second == "false")
        {
            value = false;
            return 0;
        }
        else
        {
            WARNING("The value[%s] is not bool, config name[%s]", iter->second.c_str(), name.c_str());
            return -1;
        }
    }
    else
    {
        WARNING("config name[%s] is not exit!", name.c_str());
        return -1;
    }
}
const char* StrategyInfo::GetConfigStr(const std::string& name) const
{
    std::map<std::string, std::string>::const_iterator iter = m_configMap.find(name);
    if(iter == m_configMap.end())
    {
        WARNING("config name[%s] is not exit!", name.c_str());
        return NULL;
    }
    return iter->second.c_str();
}

int StrategyInfo::InsertConfig(const std::string& name, const std::string& value)
{
    std::map<std::string, std::string>::iterator iter = m_configMap.find(name);
    if(iter != m_configMap.end())
    {
        WARNING("config name[%s] is exit!", name.c_str());
        return -1;
    }
    m_configMap[name] = value;
    return 0;
}






















/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */

